#include <QtGui>

#include "MainWindow.h"
#include "OgreWidget/OgreWidget.h"

//----------------------------------------------------------------------------------------------------------------------
MainWindow::MainWindow(QWidget* parent) :
	QMainWindow(parent),
	mDebugStats(true)
{
	mOgreWidget = new OgreWidget();
	setCentralWidget(mOgreWidget);
	mOgreWidget->initialize();
	mOgreWidget->showDebugOverlay(mDebugStats);

	createActions();
	createMenus();
	createToolBars();
	createStatusBar();

	setWindowIcon(QIcon(":/images/icon.png"));
}

//----------------------------------------------------------------------------------------------------------------------
void MainWindow::createActions()
{
	// new file action
	mNewFileAction = new QAction(tr("&New"), this);
	mNewFileAction->setIcon(QIcon(":/images/new.png"));
	mNewFileAction->setShortcut(tr("Ctrl+N"));
	mNewFileAction->setStatusTip(tr("Create a new level file"));
	connect(mNewFileAction,
			SIGNAL(triggered()),
			this,
			SLOT(newFile()));

	// open file action
	mOpenAction = new QAction(tr("&Open"), this);
	mOpenAction->setIcon(QIcon(":images/open.png"));
	mOpenAction->setShortcut(tr("Ctrl+O"));
	mOpenAction->setStatusTip(tr("Open a existing level file"));
	connect(mOpenAction,
			SIGNAL(triggered()),
			this,
			SLOT(open()));

	// save file action
	mSaveAction = new QAction(tr("&Save"), this);
	mSaveAction->setIcon(QIcon(":images/save.png"));
	mSaveAction->setShortcut(tr("Ctrl+S"));
	mSaveAction->setStatusTip(tr("Save the current level file"));
	connect(mSaveAction,
			SIGNAL(triggered()),
			this,
			SLOT(save()));

	// save as file action
	mSaveAsAction = new QAction(tr("Save As"), this);
	mSaveAsAction->setStatusTip(tr("Save the current level file under a new name"));
	connect(mSaveAsAction,
			SIGNAL(triggered()),
			this,
			SLOT(saveAs()));

	// exit action
	mExitAction = new QAction(tr("E&xit"), this);
	mExitAction->setStatusTip(tr("Close the application and ask for save"));
	connect(mExitAction,
			SIGNAL(triggered()),
			this,
			SLOT(close()));

	// show debug stats action
	mShowDebugStatsAction = new QAction(tr("Debug Statistic"), this);
	mShowDebugStatsAction->setCheckable(true);
	mShowDebugStatsAction->setChecked(mDebugStats);
	mShowDebugStatsAction->setStatusTip(tr("Toggle debug statistic on and off"));	
	connect(mShowDebugStatsAction,
			SIGNAL(toggled(bool)),
			mOgreWidget,
			SLOT(showDebugOverlay(bool)));
}

//----------------------------------------------------------------------------------------------------------------------
void MainWindow::createMenus()
{
	// create file menu
	mFileMenu = menuBar()->addMenu(tr("&File"));
	mFileMenu->addAction(mNewFileAction);
	mFileMenu->addAction(mOpenAction);
	mFileMenu->addAction(mSaveAction);
	mFileMenu->addAction(mSaveAsAction);
	mFileMenu->addSeparator();
	mFileMenu->addAction(mExitAction);

	// create view menu
	mViewMenu = menuBar()->addMenu(tr("&View"));
	mViewMenu->addAction(mShowDebugStatsAction);
}

//----------------------------------------------------------------------------------------------------------------------
void MainWindow::createToolBars()
{
	// create file toolbar
	mFileToolBar = addToolBar(tr("&File"));
	mFileToolBar->addAction(mNewFileAction);
	mFileToolBar->addAction(mOpenAction);
	mFileToolBar->addAction(mSaveAction);
}

//----------------------------------------------------------------------------------------------------------------------
void MainWindow::createStatusBar()
{

}

//----------------------------------------------------------------------------------------------------------------------
void MainWindow::newFile()
{

}

//----------------------------------------------------------------------------------------------------------------------
void MainWindow::open()
{

}

//----------------------------------------------------------------------------------------------------------------------
void MainWindow::save()
{

}

//----------------------------------------------------------------------------------------------------------------------
void MainWindow::saveAs()
{

}

//----------------------------------------------------------------------------------------------------------------------
void MainWindow::help()
{

}

//----------------------------------------------------------------------------------------------------------------------
void MainWindow::about()
{

}

